package com.ruoyi.zsyh.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.IdWorker;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Map;

import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.zsyh.domain.ZsyhPlatformPartsattribute;
import com.ruoyi.zsyh.mapper.ZsyhPlatformPartsMapper;
import com.ruoyi.zsyh.domain.ZsyhPlatformParts;
import com.ruoyi.zsyh.service.IZsyhPlatformPartsService;
import com.ruoyi.common.core.text.Convert;

/**
 * 配件管理Service业务层处理
 * 
 * @author yuexl
 * @date 2021-12-10
 */
@Service
public class ZsyhPlatformPartsServiceImpl implements IZsyhPlatformPartsService 
{
    @Autowired
    private ZsyhPlatformPartsMapper zsyhPlatformPartsMapper;

    /**
     * 查询配件管理
     * 
     * @param id 配件管理ID
     * @return 配件管理
     */
    @Override
    public ZsyhPlatformParts selectZsyhPlatformPartsById(String id)
    {
        return zsyhPlatformPartsMapper.selectZsyhPlatformPartsById(id);
    }
    @Override
    public ZsyhPlatformParts selectZsyhPlatformPartsByIdStore(String userType, String id)
    {
        return zsyhPlatformPartsMapper.selectZsyhPlatformPartsByIdStore(userType, id);
    }

    public List<ZsyhPlatformParts> selectZsyhPlatformPartsByFactoryId(String factoryId){
        return zsyhPlatformPartsMapper.selectZsyhPlatformPartsByFactoryId(factoryId);
    }

    /**
     * 查询配件管理列表
     * 
     * @param zsyhPlatformParts 配件管理
     * @return 配件管理
     */
    @Override
    public List<ZsyhPlatformParts> selectZsyhPlatformPartsList(ZsyhPlatformParts zsyhPlatformParts)
    {
        return zsyhPlatformPartsMapper.selectZsyhPlatformPartsList(zsyhPlatformParts);
    }

    public List<Map> getPartsListCheckByStoreId(String storeId){
        return zsyhPlatformPartsMapper.getPartsListCheckByStoreId(storeId);
    }

    /**
     * 新增配件管理
     * 
     * @param zsyhPlatformParts 配件管理
     * @return 结果
     */
    @Transactional
    @Override
    public int insertZsyhPlatformParts(ZsyhPlatformParts zsyhPlatformParts)
    {
        zsyhPlatformParts.setId(IdWorker.getId());
        zsyhPlatformParts.setCreateTime(DateUtils.getNowDate());
        int rows = zsyhPlatformPartsMapper.insertZsyhPlatformParts(zsyhPlatformParts);
        insertZsyhPlatformPartsattribute(zsyhPlatformParts);
        return rows;
    }

    /**
     * 修改配件管理
     * 
     * @param zsyhPlatformParts 配件管理
     * @return 结果
     */
    @Transactional
    @Override
    public int updateZsyhPlatformParts(ZsyhPlatformParts zsyhPlatformParts)
    {
        zsyhPlatformParts.setUpdateTime(DateUtils.getNowDate());
        return zsyhPlatformPartsMapper.updateZsyhPlatformParts(zsyhPlatformParts);
    }

    /**
     * 删除配件管理对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteZsyhPlatformPartsByIds(String ids)
    {
        zsyhPlatformPartsMapper.deleteZsyhPlatformPartsattributeByPartsIds(Convert.toStrArray(ids));
        return zsyhPlatformPartsMapper.deleteZsyhPlatformPartsByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除配件管理信息
     * 
     * @param id 配件管理ID
     * @return 结果
     */
    @Override
    public int deleteZsyhPlatformPartsById(String id)
    {
        zsyhPlatformPartsMapper.deleteZsyhPlatformPartsattributeByPartsId(id);
        return zsyhPlatformPartsMapper.deleteZsyhPlatformPartsById(id);
    }

    @Override
    public List<ZsyhPlatformParts> selectZsyhPartsListIn(ZsyhPlatformParts zsyhPlatformParts) {
        return zsyhPlatformPartsMapper.selectZsyhPartsListIn(zsyhPlatformParts);
    }

    /**
     * 新增产品规格管理信息
     * 
     * @param zsyhPlatformParts 配件管理对象
     */
    public void insertZsyhPlatformPartsattribute(ZsyhPlatformParts zsyhPlatformParts)
    {
        List<ZsyhPlatformPartsattribute> zsyhPlatformPartsattributeList = zsyhPlatformParts.getZsyhPlatformPartsattributeList();
        String  id = zsyhPlatformParts.getId();
        if (StringUtils.isNotNull(zsyhPlatformPartsattributeList))
        {
            List<ZsyhPlatformPartsattribute> list = new ArrayList<ZsyhPlatformPartsattribute>();
            for (ZsyhPlatformPartsattribute zsyhPlatformPartsattribute : zsyhPlatformPartsattributeList)
            {
                zsyhPlatformPartsattribute.setPartsId(id);
                list.add(zsyhPlatformPartsattribute);
            }
            if (list.size() > 0)
            {
                zsyhPlatformPartsMapper.batchZsyhPlatformPartsattribute(list);
            }
        }
    }

    public List<Map> getPartsListByTypeId(String partsType, String key, int num, int size, String agentId){
        return zsyhPlatformPartsMapper.getPartsListByTypeId(partsType, key, num, size, agentId);
    }

    public List<Map> getPartsSalesVolumeAll(Map map){
        return zsyhPlatformPartsMapper.getPartsSalesVolumeAll(map);
    }
}
